package com.shawn.baseappbygroovydsl.ui.views

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.shawn.baseappbygroovydsl.ui.adapter.ChatListAdapter
import com.shawn.baseappbygroovydsl.R
import com.shawn.baseappbygroovydsl.databinding.FragChatBinding
import com.shawn.baseappbygroovydsl.ui.base.FragmentBase
import eee.drama.idea_chat.bean.BeanRedGroup


class FragChat(layoutRes: Int = R.layout.frag_chat) : FragmentBase<FragChatBinding>(layoutRes) {
    private lateinit var layoutManager: LinearLayoutManager

    private val chatAdapter by lazy {
        val value = ChatListAdapter()
        value.setOnItemClickListener(object : BaseQuickAdapter.OnItemClickListener<BeanRedGroup> {

            override fun onClick(adapter: BaseQuickAdapter<BeanRedGroup, *>, view: View, position: Int) {
                val bean = adapter.getItem(position)
                bean?.let {_bean->
//                    showFullScreenFrag(
//                        FragChatContent.newInstance(_bean.type, _bean.title),
//                        R.anim.anim_drama_show
//                    )
                    showSubFrag(
                        FragChatContent::class.java.name,
                        FragChatContent.newInstance(_bean.type, _bean.title),
                        R.id.fl_frag_sub_container,
                        R.anim.anim_drama_show
                    )
                }
            }
        })
        value
    }

    override fun statusBar() {

    }

    override fun lazyLoad() {
        initView()
    }

    override fun initClick() {

    }

    override fun getData() {

    }

    override fun onKeyCodeBack(): Boolean {
        return false
    }

    private fun initView() {
        layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
        mBind.chatRv.layoutManager = layoutManager
        mBind.chatRv.adapter = chatAdapter

        val local = "西安"

        val list = ArrayList<BeanRedGroup>()
        list.add(BeanRedGroup(true,eee.drama.idea_chat.R.drawable.chat_red_group_icon_1,"新人好礼群","红包助手：", "新人进群领红包", "99+",
            FragChatContent.RED_GROUP_1
        ))
        list.add(BeanRedGroup(true,eee.drama.idea_chat.R.drawable.chat_red_group_icon_2,"${local}同城群","[红包]", "恭喜发财，大吉大利", "24",
            FragChatContent.RED_GROUP_2
        ))
        list.add(BeanRedGroup(true,eee.drama.idea_chat.R.drawable.chat_red_group_icon_3,"${local}同城拼手速群","", "超大红包拼手速抢", "99+",
            FragChatContent.RED_GROUP_3
        ))
        list.add(BeanRedGroup(true,eee.drama.idea_chat.R.drawable.chat_red_group_icon_4,"短剧交流群","[红包]", "恭喜发财，大吉大利", "99+",
            FragChatContent.RED_GROUP_DRAMA
        ))
        chatAdapter.submitList(list)
    }

    override fun getBind(view: View): FragChatBinding {
        return FragChatBinding.bind(view)
    }

    companion object {
        fun newInstance(): FragChat {
            val args = Bundle()
            val fragment = FragChat()
            fragment.arguments = args
            return fragment
        }
    }
}